//
//  Kylin_SquareButton.m
//  03-BuDeJie-2 TabBar设置
//
//  Created by Kylin on 16/2/11.
//  Copyright © 2016年 kylin. All rights reserved.
//

#import "Kylin_SquareButton.h"
#import "Kylin_MeSpuares.h"
#import <UIButton+WebCache.h>
@implementation Kylin_SquareButton

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        self.titleLabel.font = [UIFont systemFontOfSize:14];
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        // 每二种方法设置背景图片
        [self setBackgroundImage:[UIImage imageNamed:@"mainCellBackground"] forState:UIControlStateNormal];
    }
    return self;
}


- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    // 设置imageView的尺寸
    self.imageView.width = self.width * 0.5;
    self.imageView.height = self.imageView.width;
    
    self.imageView.y = self.imageView.height * 0.1;
    self.imageView.centerX = self.width * 0.5;
    
    // 设置文字的尺寸
    self.titleLabel.width = self.width;
    self.titleLabel.y = CGRectGetMaxY(self.imageView.frame);
    self.titleLabel.x = 0;
    self.titleLabel.height = self.height - self.titleLabel.y;
    
}

- (void)setSquare:(Kylin_MeSpuares *)square{
    
    _square = square;
    // 设置数据的
    [self setTitle:square.name forState:UIControlStateNormal];
    [self sd_setImageWithURL:[NSURL URLWithString:square.icon] forState:UIControlStateNormal];
}
@end
